package com.yyx.app1.incompatibility_function.Controls.Incompatibility_ListView_Control;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.yyx.app1.Data.DataInit;

import java.util.HashMap;
import java.util.List;

/**
 * Created by yuexing on 2015/9/8.
 */
public class Incompatibility_ListView_Adapter extends BaseAdapter {
    private Context context;
    private List map;
    private DataInit dataInit;

    public Incompatibility_ListView_Adapter(Context context)
    {
        this.context = context;
        dataInit= new DataInit(context,false,"cxlin");
    }

    public void findAll()
    {
        map = dataInit.getTabooCompatible_SQLiteOperation().getDemo_10name();
        this.notifyDataSetChanged();
    }

    public void findAll(String name)
    {
        map = dataInit.getTabooCompatible_SQLiteOperation().getItemByfirstMedicine(name);
        if (map.size()==0)
        {
            map = dataInit.getTabooCompatible_SQLiteOperation().fuzzySearch(name);
        }
        this.notifyDataSetChanged();
    }

    public List getMap() {
        return map;
    }

    @Override
    public int getCount() {
        return map.size();
    }

    @Override
    public Object getItem(int position) {
        return map.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Incompatibility_ListView_ItemView it ;
        if (convertView==null)
        {
            it = Incompatibility_ListView_ItemView_.build(context);
        }
        else
        {
            it = (Incompatibility_ListView_ItemView)convertView;
        }
        Object object =map.get(position);
        String str=null;
        if (object instanceof String)
        {
            str=(String) object;
        }
        if (object instanceof HashMap)
        {
            str = ((HashMap<String,String>) object).get("firstMedicine")+" ∷ "+((HashMap<String,String>) object).get("secondMedicine");
        }
        it.bind(position,str);
        it.getSecond_listview_ico_background().setBackground(new ColorDrawable(Color.WHITE));
        it.getSecond_listview_starttext().setTextColor(Color.rgb(255, 102, 51));
        it.getSecond_listview_text().setTextColor(Color.BLACK);
        it.getSecond_listview_text().setTextSize(14);
        it.getSecond_listview_text().setPadding(0,0,0,0);
        return it;
    }
}
